<template>
  <div></div>
</template>

<script>
import { getUserByToken } from '@/api/common'
import { userRecentlyPro } from '@api/login'
import { getProjectList } from '@/api/overview/contract'
export default {
  async created() {
    const token = this.$route.query.token
    if (token) {
      await getUserByToken({ token })
      localStorage.setItem('Access-Token', JSON.stringify(token))
      this.$store.commit('SET_TOKEN', token)
      const info = await userRecentlyPro({})
      const list = await getProjectList({
        pageNumber: 1,
        pageSize: 10000
      })
      console.log('list', list)
      localStorage.setItem('CURRENT_ROLECODE', info.roleCode)
      localStorage.setItem(
        'CURRENT_PROJECT_LIST',
        JSON.stringify(list.page.content)
      )
      const record = info.proInfo || list.page.content[0]
      this.$store.dispatch('EnterProject', record).then((e) => {
        if (list.page.totalCount > 0) {
          this.$router.replace('/high')
        } else {
          this.$router.replace('/403?btnShow=loginByToken')
        }
      })
    }
  }
}
</script>
